<form action="" method="post">
    <input type="submit" name="start" value="开始答题">
    <input type="submit" name="stop" value="开始完毕">
</form>
<?php
/**
 * User: lie
 * Date: 2020/12/11 11:55
 * Title: 计算考试时间
 * Description:
 * Error:
 */
session_start();
if ($_POST['start']) {
    $time = time();
    $_SESSION['start'] = $time;
    echo "<script> alert('单击开始答题');</script>";
}-

if ($_POST['stop']) {
    if (isset($_SESSION['start'])) {
        echo "您用时：".(time()-$_SESSION['start']).'秒答题';
        session_destroy();
    } else {
        echo "<script> alert('您还没有答题无法结束，请先答题');</script>";
    }
}
